define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shopgoods/index' + location.search,
                    add_url: 'shopgoods/add',
                    edit_url: 'shopgoods/edit',
                    multi_url: 'shopgoods/multi',
                    import_url: 'shopgoods/import',
                    table: 'shop_goods',
                },
                showExport:false
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                commonSearch: true,
                visible: true,
                showToggle: false,
                showColumns: false,
                search:false,
                searchFormVisible:true,
                showExport: false,
                columns: [
                    [
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'goods.cover_img', title: '封面图',vents: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'goods.goods_name', title: __('Goods'),operate: 'like'},
                        {field: 'shop.shop_name', title: '归属店铺',operate: 'like'},
                        {field: 'market_price', title: '市场价', operate: false,sortable: true},
                        // {field: 'price', title: '销售价格', operate: false,sortable: true},
                        {field: 'cost', title: __('Cost'), operate: false,sortable: true},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE',sortable: true, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.flag, searchList: {1:"上架", 0: "下架"}},
                        {field: 'audit_status', title: __('Audit_status'), formatter: Table.api.formatter.flag, searchList: {1:"通过", 2:"拒绝", 0: "待审核"}},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
